<template>
  <div class="search">
    <div class="back">
      <span class="iconfont" @click="back">&#xe613;</span>
    </div>
    <div class="search-top">
      <mt-search cancel-text="取消" placeholder="搜影院"></mt-search>
    </div>
    <div class="search-result" v-if="flag">
      <div class="result">
        <h3>影院</h3>
        <ul class="list">
          <li class="info" v-for="item in list" :key="item.id">
            <div class="desc">
              <p class="name-price">
                <span class="name one-line">{{item.nm}}</span>
                <span class="sell-price">
                  <span class="price">{{item.sellPrice}}</span> 元起
                </span>
              </p>
              <p class="address one-line">{{item.addr}}</p>
              <p class="feature-tags">
                <span>座</span>
                <span v-if="item.allowRefund">退</span>
                <span v-if="item.endorse">改签</span>
                <span v-for="(i,index) in item.hallType" :key="index">{{i}}</span>
                <span class="featrue">小吃</span>
              </p>
            </div>
            <div class="distance">1.1km</div>
          </li>
        </ul>
        <div class="more-result" @click="goList" v-if="this.flag1">查看全部{{count}}家电影院</div>
      </div>
    </div>
    <div class="nothing" v-if="this.flag2">
      <p>没有找到相关影院</p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: "",
      list: [],
      count: 0,
      allData: [], //请求的所有数据
      flag: false,
      flag1: false, //当this.count小于等于3时 让其隐藏
      flag2: false
    };
  },
  methods: {
    getData() {
      this.$axios
        .get("http://www.softeem.xin/maoyanApi/ajax/search", {
          params: {
            kw: this.value,
            cityId: 59,
            type: 2
          }
        })
        .then(res => {
          this.list = res.data.cinemas && res.data.cinemas.list.slice(0, 3);
          this.allData = res.data.cinemas;
          this.count = res.data.cinemas && res.data.cinemas.list.length;
          // console.log(this.list)
          // console.log(this.allData,this.count)
          if (this.count > 3) {
            this.flag1 = true;
          }
          if (this.count === undefined) {
            //没有请求到数据时   用flag来控制页面的显示
            this.flag = false;
            this.flag2 = true;
          } else {
            this.flag = true;
            this.flag2 = false;
          }
        });
    },
    back() {
      this.$router.push("/home/cinema");
    },
    goList() {
      this.$router.push("/cinemalist");
      sessionStorage.setItem("data", JSON.stringify(this.allData));
    }
  },
  mounted() {
    $(".navBar").css({ "z-index": 0 });
    $(".mint-searchbar-cancel").click(() => {
      location.href = "/home/cinema";
    });
    $(".mint-searchbar-core").keyup(() => {
      this.value = $(".mint-searchbar-core").val();
      if (this.value.length === 0) {
        this.flag = false;
      } else {
        this.getData();
      }
    });
    $(".mint-searchbar-core").click(() => {
      this.value = $(".mint-searchbar-core").val("");
      this.flag = false;
      this.flag2 = false;
    });
  }
};
</script>

<style scoped lang="scss">
.search {
  .back {
    position: fixed;
    top: 0.22rem;
    left: 0.16rem;
    z-index: 20;
    span {
      font-size: 0.48rem;
    }
    color: white;
  }
  .search-top {
    width: 100%;
    height: 0.94rem;
    position: fixed;
    top: 1rem;
    left: 0;
    .mint-search {
      height: 100%;
    }
  }
  .search-result {
    font-size: 0.28rem;
    color: #777;
    width: 100%;
    max-height: 8rem;
    margin-bottom: 0.2rem;
    margin-top: 1.94rem;
    background-color: #fff;
    h3 {
      font-size: 0.3rem;
      color: #999;
      padding: 0.18rem 0.3rem;
      font-weight: 400;
    }
    .list {
      padding-left: 0.3rem;
      border-top: 1px solid #e6e6e6;

      .info {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.3rem 0.3rem 0.3rem 0;
        border-bottom: 1px solid #e6e6e6;
        .desc {
          flex: 1;
          overflow: hidden;
          .name-price {
            font-size: 0.32rem;
            color: #000;
            margin-bottom: 0.12rem;
            display: flex;
            .name {
              max-width: 4.7rem;
              white-space: nowrap;
              text-overflow: ellipsis;
              overflow: hidden;
            }
            .sell-price {
              font-size: 0.22rem;
              color: #999;
              white-space: nowrap;
              margin-left: 0.2rem;
              .price {
                font-size: 0.34rem;
                color: #ef4238;
              }
            }
          }
          .address {
            font-size: 0.26rem;
            color: #999;
            max-width: 6.14rem;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
          }
          .feature-tags {
            margin-top: 0.14rem;
            display: flex;
            span {
              border: 1px solid #589daf;
              color: #589daf;
              position: relative;
              display: inline-block;
              padding: 0 3px;
              line-height: 0.3rem;
              height: 0.3rem;
              border-radius: 2px;
              font-size: 0.26rem;
              margin-right: 0.1rem;
            }
            .featrue {
              color: #f90;
              border-color: #f90;
            }
          }
        }
        .distance {
          font-size: 0.26rem;
          color: #999;
        }
      }
    }
    .more-result {
      font-size: 0.3rem;
      color: #ef4238;
      line-height: 0.88rem;
      text-align: center;
      border-top: 1px solid #e6e6e6;
    }
  }
  .nothing {
    // display: none;
    width: 100%;
    font-size: 0.32rem;
    color: #999;
    text-align: center;
    margin-top: 1.94rem;
  }
}
</style>




